package com.evergrande.mybatis.controller;

import com.evergrande.mybatis.model.ExpandUser;
import com.evergrande.mybatis.pojo.EasyUIResult;
import com.evergrande.mybatis.service.ExpandUserService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by yyccb on 2016-8-17.
 */
@RequestMapping("/rest/extUser")
@Controller
public class ExpandUserController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ExpandUserController.class);

    @Autowired
    private ExpandUserService expandUserService;

    @ResponseBody
    @RequestMapping("list")
    public ResponseEntity<EasyUIResult> getExpandUserList(ExpandUser expandUser, @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                          @RequestParam(value = "rows", defaultValue = "30") Integer rows) {
        try {
            if (LOGGER.isDebugEnabled()) {
                // 输出输入的参数信息
                LOGGER.debug("执行查询外部拓展客户列表操作， page = {}, rows = {}", page, rows);
            }
            List<ExpandUser> list = this.expandUserService.selectListByExpandUser(expandUser, page, rows);
            PageInfo<ExpandUser> pageInfo = new PageInfo<ExpandUser>(list);
            return ResponseEntity.ok(new EasyUIResult(pageInfo.getTotal(), pageInfo.getList()));
        } catch (Exception e) {
            LOGGER.error("查询用户失败, page = " + page + ", rows = " + rows, e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }


}
